﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Authorization.AccessToken/AccessTokenExtensions 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       AccessTokenExtensions
* 创建时间：  2025/5/24 11:47:46
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Authorization.AccessToken
{
    public static class AccessTokenExtensions
    {
        public static AuthenticationBuilder AddAccessToken(this AuthenticationBuilder builder)
        {
            return builder.AddAccessToken(GlobalConfigAuth.AuthenticationScheme, delegate
            {
            });
        }

        public static AuthenticationBuilder AddAccessToken(this AuthenticationBuilder builder, Action<AccessTokenOptions> configureOptions)
        {
            return builder.AddAccessToken(GlobalConfigAuth.AuthenticationScheme, configureOptions);
        }

        public static AuthenticationBuilder AddAccessToken(this AuthenticationBuilder builder, string authenticationScheme, Action<AccessTokenOptions> configureOptions)
        {
            return builder.AddAccessToken(authenticationScheme, null, configureOptions);
        }

        public static AuthenticationBuilder AddAccessToken(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<AccessTokenOptions> configureOptions)
        {
            builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<AccessTokenOptions>, AccessTokenPostConfigureOptions>());
            return builder.AddScheme<AccessTokenOptions, AccessTokenHandler>(authenticationScheme, displayName, configureOptions);
        }
    }
}
